<include file="Public/head" />
<script src="{:get_style_cdnurl()}paimai/yunying/plugin/ztree/jquery.ztree.core-3.5.js" type="text/javascript"></script>
<style>
    #bc_city{
         -moz-appearance: none;background: rgba(0, 0, 0, 0) url("http://img2.isou365.cn/paimai/yunying/images/sanjiao.jpg") no-repeat scroll 130px 5px;border: 1px solid #d7d7d7;color: #666;float: left;
        font-family: "微软雅黑";font-size: 12px;height: 26px;line-height: 26px;margin: 0 10px 10px 10px;text-align: left;width: 154px;text-indent: 10px;
    }
</style>
<script type="text/javascript">
    var setting = {
        data: {
            simpleData: {
                enable: true
            }
        },
        callback:{
            onClick: zTreeOnClick
        }
    };

    var zNodes =[
    <?php foreach($departs as  $item):?>
    {id:<?php echo $item['id'];?>, pId:<?php echo $item['pid'];?>, name:"<?php echo $item['name'];?>",<?php echo $item['id']==1 ? "open: true" : '' ;?>},
    <?php endforeach;?>
    ];

    function zTreeOnClick( event, treeId, treeNode){
        //console.log(treeNode);
        $("#depart_id").val(treeNode.id);
        $("#onadd").val(treeNode.name);
        $(".popup ul .zTreeDemoBackground").fadeOut();
    }
    $(document).ready(function(){
        $.fn.zTree.init($("#tree"), setting, zNodes);

        $(".popup ul .bumen").click(function(){
            $(".popup ul .zTreeDemoBackground").fadeToggle();
        })

        $("#onadd").click(function(){
            $(".popup ul .zTreeDemoBackground").fadeToggle();
        })
    });
</script>
</head>
<body>
    <include file="Public/common_header" />
    <div class="mian">
        <include file="Public/sidebar" menu='zhgl.ygzh' />
        <div class="mianR">
            <div class="listBox">
                <form id="fm" action="/Emp/index" method="GET">
                <div class="yuList">
                    <select name="bc_city" id="bc_city">
                        <?php if ($is_hq): ?>
                         <option value="">请选择所属部门</option>   
                        <?php endif ?>
                        <?php foreach ($bc_list as $k => $v): ?>
                            <option value="{$k}" 
                            <?php if (I('get.bc_city') == $k): ?>
                                selected="selected"
                            <?php endif ?>
                            >{$v}</option>
                        <?php endforeach ?>
                    </select>
                    <div class="deng-ji">
                        <input type="hidden" id="p" name='p' value="" />
                        <input type="text" name='search_key' value="{:I('get.search_key')}" placeholder="账号、姓名、电话"></div>
                    <div class="shangSou">
                        <input type="button" onclick="$('#fm #p').val('');$('#fm').submit();" value="搜索"></div>
                    <div class="xinzeng clearfix">
                        <input type="button" onclick="create_emp();" value="新增员工" />
                        <a class="fenzu" href="/Emp/group_list" >权限分组管理</a>
                    </div>
                    <div class="yuListCo" style="width:1000px;">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>账号</th>
                                <th>姓名</th>
                                <th>电话</th>
                                <th>分组</th>
                                <th>部门所属</th>
                                <th>状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($list as $key => $emp): ?>
                                <tr>
                                    <td>{$emp.emp_id}</td>
                                    <td>{$emp.username}</td>
                                    <td>{$emp.real_name}</td>
                                    <td>{$emp.mobile}</td>
                                    <td class="grouping-hover">
                                       <em>{$emp.groups}</em>
                                        <div class="grouping">
                                            {$emp.groups}
                                        </div>
                                    </td>
                                    <td>{$emp.name}</td>
                                    <td>{$emp['status']?'禁用':'启用'}</td>
                                    <td>{$emp.createtime}</td>
                                    <td>
                                        <a href="/Emp/set_group/emp_id/{$emp.emp_id}" >设置权限</a>
                                        <a href="javascript:;" onclick="restpwd('{$emp.username}');">重置密码</a>
                                        <a href="/Emp/edit/username/{$emp.username}" >编辑</a>
                                        <if condition="($emp.status eq 0)">
                                            <a href="" onclick="return ci_op('{$emp.username}',1);">禁用</a>
                                            <else />
                                            <a href="" onclick="return ci_op('{$emp.username}',0);">启用</a>
                                        </if>
                                        <a href="" onclick="return ci_op('{$emp.username}',-1);">删除</a>
                                    </td>
                                </tr>
                            <?php endforeach ?>
                            </tbody>
                        </table>
                    </div>

                    <div class="pageFaye">
                        <div class="pager">
                            <span name="first" class="disabled" style="cursor: default;"><a num="{$page_data.first.num}" href="{$page_data.first.url}">首页</a></span>
                            <span name="prev" class="disabled" style="cursor: default;"><a num="{$page_data.prev.num}" href="{$page_data.prev.url}">上一页</a></span>
                            <span name="nav_fix" style="cursor: pointer;">
                                <?php foreach ($page_data['link_page'] as $page => $link): ?>
                                    <?php if($page == $p){ ?>
                                        <a class="navi"  num="<?php echo $page;?>" href="<?php echo $link;?>">
                                            <font style="color:#fff"><?php echo $page;?></font>
                                        </a>    
                                    <?php }else{?>
                                        <a class="navi"  num="<?php echo $page;?>" href="<?php echo $link;?>">
                                            <?php echo $page;?>
                                        </a>
                                    <?php }?>
                                <?php endforeach ?>                                
                            </span>
                            <span name="next" class="pageNext" style="cursor: pointer;"><a num="{$page_data.next.num}"  href="{$page_data.next.url}">下一页</a></span>
                            <span name="last" class="pageLast" style="cursor: pointer;"><a num="{$page_data.end.num}"  href="{$page_data.end.url}">末页</a></span>
                        </div>
                        <div class="clear"></div>
                    </div>
                    <script type="text/javascript">
                        $('#fm .pageFaye a').click(function(){
                            $('#p').val($(this).attr('num'));
                            $('#fm').submit();
                            return false;
                        });
                    </script>
                </div>
                </form>
            </div>
        </div>
        <div class="clear"></div>
    </div>
<div class="popup_group" style="margin-top: -259.5px;display:none;">

<div class="yunBei" style="display: none;"></div>
</div>
<div class="add_e_popup popup" style="margin-top: -259.5px;display:none;">
    <a href="" ><h3>员工信息填写</h3></a>
    <form id='ct_fm' action="/Emp/ci_create_emp" method="POST">
    <input name="emp_id" value="" type="hidden" />
    <ul>
        <li class="clearfix">
            <span>*用户名</span>
            <input type="text" name="username" value=""></li>
        <li class="clearfix">
            <span>*真实姓名</span>
            <input type="text" value="" name="real_name">
        </li>
        <li class="clearfix">
            <span>*用户密码</span>
            <input type="text" value="" name="passwd">
        </li>
        <li class="clearfix">
            <span>*手机</span>
            <input type="text" value="" name="mobile">
        </li>
        <li class="clearfix">
            <span>邮箱</span>
            <input type="text" value="" name="email">
        </li>
        <input type='hidden' id='depart_id' name="depart_id" value="" />
        <li class="clearfix popup-btn">
            <span>*所属部门</span>
            <input type="text" id="onadd" readonly value="">
            <div class="zTreeDemoBackground left">
                <ul id="tree" class="ztree"></ul>
            </div>
        </li>
<!--         <input type='hidden' id='store' name="store" value="" /> -->
<!--         <li class="popup-btn clearfix">
            <span>门店</span>
            <input type="text" value="总部" readonly="">
            <ul class="popup-list" style="display: none;">
                <?php foreach ($store as $key => $value): ?>
                    <li onclick="$('#store').val('<?php echo $key;?>');popup(this);" store_id="<?php echo $key;?>"><?php echo $value ?></li>    
                <?php endforeach ?>
            </ul>
        </li> -->

<!--         <input type='hidden' id='group_id' name="group_id" value="" /> -->
        <!--<li class="popup-btn clearfix">
            <span>用户分组</span>
            <input type="text" value="评估师" readonly="">
            <ul class="popup-list" style="display: none;">
                <?php foreach ($glist as $key => $value): ?>
                    <li onclick="$('#group_id').val('<?php echo $key;?>');popup(this);" group_id="<?php echo $value['id'];?>"><?php echo $value; ?></li>
                <?php endforeach ?>
            </ul>
        </li>
        -->
        <li class="clearfix">
            <input type="button" value="确定" class="queding">
            <input type="button" value="取消" class="quxiao">
        </li>
    </ul>
    </form>
</div>

    <script>

    $(document).ready(function(){
        $(".table tbody .grouping-hover").each(function(){
            $(this).hover(function(){
                $(this).find("div").show();
            },function(){
                $(this).find("div").hide();
            })
        })
    })

function create_emp(){
    var bg = $('.yunBei'),pp = $('.add_e_popup'),cfm=$('.queding'),cl=$('.quxiao');
    bg.show();
    pp.show();
    $([bg,cfm,cl]).each(function(i,n){
        $(n).unbind('click');
    });
    bg.click(hide_pp);    
    cl.click(hide_pp);
    cfm.click(function(){
        post_submit_json('ct_fm',function(data){
            //成功回调
            delay_alert('添加员工成功',300);
            setTimeout(function(){
                //window.location.reload();    
                location.href='/Emp/index';
            },300);
        });
    });
    function hide_pp(){
        bg.hide();
        pp.hide();
        bg.unbind('click');
    };
};

function ci_op(username,op_type){
    var post_data = {username:username,op_type:op_type};
    $.post('/Emp/ci_op',post_data,function(res){
        if(res.code==200){
            delay_alert('操作成功!');
            setTimeout(function(){
                //window.location.reload();    
                location.href='/Emp/index';
            },300);
        }else{
            delay_alert(res.msg);
        }
    },'json');
    return false;
};

// function restpwd(username){
//     var aa = confirm('确认重置密码吗?');
//     if (aa == true) {
//         var post_data = {username:username};
//         $.post('/Emp/restpwd',post_data,function(res){
//           if(res.code=='200'){
//                 alert('重置成功!');
//                 setTimeout(function(){  
//                     location.href='/Emp/index';
//                 },300);
//             }else{
//                 alert('重置失败!');
//             }
//         }, "json");
//     }else{
//         return false;
//     }
// }
    function restpwd(username){
        confirmAAA('<div style="color:red">确认重置密码吗？</div>', confirm11);
        function confirm11() {
            $('.determine').click(function() {
                colse_hideA();
                arestpwd(username);
            });
        }
    }
   

    function confirmAAA(text,callback){
        var html='<div class="chenggong1"><span class="paidan">'+text+'</span><div class="shenhei-btn"><input type="button" value="确定" class="determine" /><input type="button" value="取消" class="cancel" onclick="colse_hide()" /></div></div>'
        $(".yunBei").css("display","block");
        $(document.body).append(html);
        $(".chenggong1").css("display","block");
        if(typeof(callback)!="undefined"){
            callback();
        }
    }
    function colse_hideA(){
        $(".yunBei").css("display","none");
        $(".chenggong1").fadeOut('slow',function(){
            $(".chenggong1").remove();
        });
    }   
    function arestpwd(username){
        $.post("/Emp/restpwd",{'username':username}, function (data) {
            if(data.code=='200'){
                var curr_char = $('input[name=char]').val();
                btn_alert(data.msg,2,function(){
                    $(".fchar").each(function (i) {
                        if ($(this).text().trim() == curr_char) {
                            $(this).click();
                        }
                    });
                });
            }else{
                shibai_alert(data.msg);
            }
        }, "json");
    }


//$(function() {
//    $( ".add_e_popup").draggable();
//})
</script>
<include file="Public/foot" />